<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8"/>
    <title>导入</title>
    <link href="__STATIC__/component/pear/css/pear.css" rel="stylesheet"/>
</head>
<body class="childrenBody {:dialog_css()}">

<form class="layui-form" action="{:url('import')}?model_id={$model_id}" method="post">

    <blockquote class="layui-elem-quote layui-font-red">可删除表和原字段！同名字段导入会重命名！</blockquote>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-item-required">删表和原字段</label>
        <div class="layui-input-group">
            <input type="hidden" name="is_clear" value="0">
            <input type="checkbox" name="is_clear" value="1" lay-skin="switch" lay-text="是|否" />
        </div>
    </div>

    <blockquote class="layui-elem-quote">可先配置预设字段，再进行导入。</blockquote>

    <div class="layui-form-item">
        <label class="layui-form-label">从预设导入</label>
        <div class="layui-input-block">
            {:form_select('field_ids', widget('field')->get(), '', ' xm-select="field" xm-select-skin="normal"')}
        </div>
    </div>

    <blockquote class="layui-elem-quote">可先上传csv数据文件，再进行导入。</blockquote>

    <div class="layui-form-item">
        <label class="layui-form-label">从文件导入</label>
        <div class="layui-input-block">
            <div class="layui-col-xs7">
                <input type="text" name="data_file" value="" placeholder="数据文件路径" id="data_file" lay-affix="clear" class="layui-input" readonly />
            </div>
            <div class="layui-col-xs5">&nbsp;
                <button type="button" class="layui-btn aphp-upload" id="ID-upload-data_file" data-url="{:url('api/upload')}?api=excel" data-field="data_file" data-accept="file" lay-options="{accept:'file',exts:'csv|xls'}">
                    <i class="layui-icon layui-icon-upload" style="color:#fff;"></i>上传
                </button>
                <button type="button" class="layui-btn" id="data_file-selected" data-url="{:url('attach/selected')}?type=excel">
                    <i class="layui-icon layui-icon-slider" style="color:#fff;"></i> 选择
                </button>
            </div>
        </div>
    </div>


    <div class="layui-form-item layer-footer">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="save">
                <i class="layui-icon layui-icon-ok"></i>
                导入
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>

<script src="__STATIC__/component/layui/layui.js"></script>
<script src="__STATIC__/component/pear/pear.js"></script>
<script>
    layui.use(['aphpForm', 'aphp', 'form'], function () {
        var aphpForm = layui.aphpForm,
            aphp = layui.aphp,
            form = layui.form;

        aphpForm.bindEvent('form.layui-form'); // 渲染表单

        form.on('submit(save)', function (data) {
            aphp.request.postForm(data, 0, function () {
                parent.layer.close(parent.layer.getFrameIndex(window.name));
                parent.layui.table.reload('currentTable');
            }, function () {
                parent.layui.table.reload('currentTable');
            });
            return false;
        });
    })
</script>
</body>
</html>